package com.zhdl.websocket.client;

import lombok.extern.slf4j.Slf4j;
import org.java_websocket.client.WebSocketClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.net.URI;

/**
 * @Description:
 * @author: liu zhenming
 * @date: 2023/8/18 9:52
 */
@Slf4j
@RestController
@RequestMapping("/socket")
public class ClientTest {

    private WebSocketClient webSocketClientExample;

    @GetMapping("/link")
    public String testPush() throws Exception {
        webSocketClientExample = new WebSocketClientExample(new URI("ws://127.0.0.1:8080/ws"));
        webSocketClientExample.connect();
        return "ok";
    }

    @GetMapping("/push/{msg}")
    public String testPush(@PathVariable("msg") String string) throws Exception {
        webSocketClientExample.send(string);
        return "ok";
    }


}
